package promote.brozen.spring.importsource;

import lombok.Setter;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.*;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

/**
 * @author Brozen
 * @date 2020/8/31 8:59 AM
 * @email brozen@qq.com
 */
@Configuration
@ComponentScan(basePackageClasses = ImportSourceTest.class)
@PropertySource("classpath:test.properties")
public class ImportSourceTest {

    public static void main(String[] args) {
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(ImportSourceTest.class);
        applicationContext.getBean(TestBean.class).print();
    }


    @Component
    public static class TestBean implements EnvironmentAware, InitializingBean {

        @Setter
        private Environment environment;

        @Override
        public void afterPropertiesSet() {
            System.out.println(environment.getProperty("msg"));
        }

        public void print() {
            System.out.println(environment.getProperty("msg"));
        }
    }

}
